package com.dcits.agent;

import advice.org.springframework.util.ClassUtilsAdvice;
import com.dcits.agent.loader.SmartClassLoader;
import net.bytebuddy.agent.ByteBuddyAgent;

import java.util.ServiceLoader;

/**
 * @className: AdviceInstall
 * @description:
 * @author: caoyangjie
 * @date: 2025/6/5
 **/
public class AdviceInstall {
    public static void install() {
        ByteBuddyAgent.install();
        SmartClassLoader classLoader = SmartClassLoader.getInstance();
        Thread.currentThread().setContextClassLoader(classLoader);
        ServiceLoader<IAdvice> serviceLoader = ServiceLoader.load(IAdvice.class);
        serviceLoader.forEach(IAdvice::advice);
        // 手动加载并升级 servlet 版本
        String[] manualLoadSets = new String[]{
                "cn.com.zybank.msp.smartcloud.auth.client.util.ZYBankHeadUtil",
                "cn.com.zybank.msp.smartcloud.auth.client.util.ZYHeadBean"
        };
        for (String className : manualLoadSets) {
            ClassUtilsAdvice.replaceClass(className);
        }
    }
}
